//
// Created by win10 on 2024/12/30.
//
#include <stdio.h>
#include <stdlib.h>

#define MAX_SIZE 100

// 交换两个整数
void swap(int *a, int *b) {
    int temp = *a;
    *a = *b;
    *b = temp;
}

// 冒泡排序
void bubbleSort(int arr[], int n) {
    for (int i = 0; i < n - 1; i++) {
        for (int j = 0; j < n - i - 1; j++) {
            if (arr[j] > arr[j + 1]) {
                swap(&arr[j], &arr[j + 1]);
            }
        }
    }
}

// 二分查找
int binarySearch(int arr[], int n, int target) {
    int left = 0;
    int right = n - 1;
    while (left <= right) {
        int mid = (left + right) / 2;
        if (arr[mid] == target) {
            return mid + 1;
        } else if (arr[mid] < target) {
            left = mid + 1;
        } else {
            right = mid - 1;
        }
    }
    return 0;
}

int main() {
    int n;
    while (scanf("%d", &n)!= EOF) {
        int arr[MAX_SIZE];
        for (int i = 0; i < n; i++) {
            scanf("%d", &arr[i]);
        }
        bubbleSort(arr, n);

        int m;
        scanf("%d", &m);
        int query[MAX_SIZE];
        for (int i = 0; i < m; i++) {
            scanf("%d", &query[i]);
        }

        // 输出排序后的结果
        for (int i = 0; i < n; i++) {
            printf("%d%s", arr[i],i == n-1?"":" ");
        }
        printf("\n");

        // 进行二分查找并输出结果
        for (int i = 0; i < m; i++) {
            int result = binarySearch(arr, n, query[i]);
            printf("%d%s", result,i == m-1?"":" ");
        }
        printf("\n");
    }
    return 0;
}